<?php

namespace app\common\model\Post;

use think\Model;

class Fans extends Model
{
  //标志当前模型操作的是哪张表
  protected $name = "post_fans";

  //开启自动写入
  protected $autoWriteTimestamp = true;
  protected $createTime = 'createtime';
  protected $updateTime = false;

  // 追加属性
  protected $append = [
    'createtime_text',
  ];

  // 时间获取器方法
  public function getCreateTimeTextAttr($value, $data)
  {
    // 获取时间
    $createtime = isset($data['createtime']) ? trim($data['createtime']) : '';

    // 判断是否为空，不为空就转换为时间戳
    if (empty($createtime)) {
      return '';
    }
    return date('Y-m-d H:i', $createtime);
  }

  public function business()
  {
    return $this->belongsTo('app\common\model\Business\Business', 'busid', 'id', [], 'LEFT')->setEagerlyType(0);
  }
}
